package com.lsl.endworkvol.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lsl.endworkvol.dao.SignUpNoteMapper;
import com.lsl.endworkvol.entity.SignUpNote;
import com.lsl.endworkvol.service.ActivityScoreService;
import com.lsl.endworkvol.service.func.ISignUpNoteBuilder;

@Service
public class ActivityScoreServiceImpl implements ActivityScoreService {

    @Autowired
    private SignUpNoteMapper signUpNoteMapper;

    @Override
    public SignUpNote getNote(Integer id) {
        return signUpNoteMapper.selectById(id);
    }

    @Override
    public List<SignUpNote> getNotes(ISignUpNoteBuilder builder) {
        SignUpNote temp = builder.build();
        if(temp.getScore() != null || temp.getCheckOutFlag() != null) {
            /// 模糊查询
            return signUpNoteMapper.blur(temp);
        }
        if (temp.getActivityId() != null && temp.getVolunteerId() == null) {
            /// 根据活动id查询
            return signUpNoteMapper.selectByActivityId(temp.getActivityId());
        } else if (temp.getActivityId() == null && temp.getVolunteerId() != null) {
            /// 根据志愿者的用户id查询
            return signUpNoteMapper.selectByVolunteerId(temp.getVolunteerId());
        } else if (temp.getActivityId() != null && temp.getVolunteerId() != null) {
            /// 根据活动id和志愿者id查询
            return signUpNoteMapper.selectByUserIdAndActivityId(temp);
        } else {
            /// 错误的查询输入
            System.out.println("[ActivityScoreServiceImpl] +++++ 错误的 getNotes 查询输入");
            return null;
        }
    }

    @Override
    public boolean score(ISignUpNoteBuilder builder) {
        SignUpNote note = builder.build();
        note.setActivityId(signUpNoteMapper.selectById(note.getId()).getActivityId());
        note.setVolunteerId(signUpNoteMapper.selectById(note.getId()).getVolunteerId());
        note.setCheckOutFlag(1);
        return signUpNoteMapper.update(note) > 0;
    }

}
